package net.jsoft.pms.mapper.jcqd;

import org.apache.commons.lang3.StringUtils;

public class JcptProvider
{
    public String getJcqdListByParams(String sszb, String beginDate, String endDate, String optUser, String zt, String copyFlag, String jcqdId)
    {

        StringBuilder sbf = new StringBuilder();
        sbf.append("SELECT distinct t.jc_mainlist_id,t.memo,t.group_id,t.creator,t.jc_state,t.CREATEDATE,t.EDITDATE,t.COPY_FLAG FROM HX_TOOLS.JCQD_MAINLIST t WHERE 1=1 ");
        if (StringUtils.isNotEmpty(sszb))
        {
            sbf.append(" and t.group_id in( ").append(sszb).append(") ");
        }
        if (StringUtils.isNotEmpty(beginDate) || StringUtils.isNotEmpty(endDate))
        {
            if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate))
            {
                sbf.append(" and (t.createdate between to_date('").append(beginDate).append("','yyyy-MM-dd') and  to_date('").append(endDate).append("','yyyy-MM-dd') or t.editdate between to_date('")
                        .append(beginDate).append("','yyyy-MM-dd') and  to_date('").append(endDate).append("','yyyy-MM-dd') ) ");
            }
            else
            {
                if (StringUtils.isNotEmpty(beginDate))
                {
                    sbf.append(" and (t.createdate >= to_date('").append(beginDate).append("','yyyy-MM-dd')   or t.editdate >=  to_date('").append(beginDate).append("','yyyy-MM-dd')  )");
                }
                if (StringUtils.isNotEmpty(endDate))
                {
                    sbf.append(" and (t.createdate <= to_date('").append(endDate).append("','yyyy-MM-dd')   or t.editdate <=  to_date('").append(endDate).append("','yyyy-MM-dd')  )");
                }
            }

        }
        if (StringUtils.isNotEmpty(optUser))
        {
            sbf.append(" and t.creator = '").append(optUser).append("'");
        }
        if (StringUtils.isNotEmpty(zt))
        {
            sbf.append(" and  t.jc_state = '").append(optUser).append("'");
        }
        if (StringUtils.isNotEmpty(jcqdId))
        {
            sbf.append(" and  t.jc_mainlist_id = '").append(jcqdId).append("'");
        }
        if (StringUtils.isNotEmpty(copyFlag))
        {
            sbf.append(" and  t.copy_flag = '").append(copyFlag).append("'");
        }
        sbf.append("  order by editdate desc ");
        return sbf.toString();
    }

}
